#include "stdafx.h"
#include "FS_map.h"


void FS_InitFile( FSFile *p_file )
{
	//do nothing
}

BOOL FS_OpenFile( FSFile *p_file, const char *path )
{
	p_file = fopen(path, "rb");
	
	return (p_file != NULL);
}

BOOL FS_CloseFile( FSFile *p_file )
{
	return (fclose(p_file) == 0);
}

u32 FS_GetLength( FSFile *p_file )
{
	int pos = ftell(p_file);
	fseek(p_file, 0, SEEK_END);
	int len = ftell(p_file);
	fseek(p_file, pos, SEEK_SET);
	
	return len;
}

s32 FS_ReadFile( FSFile *p_file, void *dst, s32 len )
{
	int pos = ftell(p_file);
	
	fread(dst,len,1,p_file);
	
	if (ferror(p_file))
		return -1;
		
	return (ftell(p_file)-pos);
}

BOOL FS_SeekFile( FSFile *p_file, s32 offset, FSSeekFileMode origin )
{
	return fseek(p_file, offset, origin);
}